package splash.core.security;

// r = read
// w = write
// x = execute
// s = screen
// a = ad-ons
// d = delete
// u = shutdown
// i = message

public class Restriction
{
	private RestrictionType type;
	private String desc;
	
	//parse
	public Restriction(String p)
	{
		//matcher check
		//oblika:
		//<vrsta omejitve>:<razlaga>|<operandi>
		if(!p.matches("^[rwxascudi]:.*$"))
			throw new IllegalArgumentException("Omejitev ni v redu.");
		setType( p.charAt(0) );
		this.desc = p.substring( p.indexOf(':') + 1 );
	
	}

        public RestrictionType getType()
        {
            return this.type;
        }

        public String getDesc()
        {
            return this.desc;
        }

	private void setType(char c)
	{
		switch(c)
		{
			case 'r':
				type = RestrictionType.READ;
				break;
			case 'w':
				type = RestrictionType.WRITE;
				break;
			case 'x':
				type = RestrictionType.EXECUTE;
				break;
			case 's':
				type = RestrictionType.SCREEN;
				break;
			case 'a':
				type = RestrictionType.ADDONS;
				break;
			case 'd':
				type = RestrictionType.DELETE;
				break;
			case 'u':
				type = RestrictionType.SHUTDOWN;
				break;
			case 'i':
				type = RestrictionType.MESSAGE;
				break;
			default:
				type = RestrictionType.UNKNOWN;
		}
	}
	
	//naprošamo, da se ne dotika tega konstruktorja. hvala.
	protected Restriction()
	{
	}
}
